﻿<UserControl x:Class="FR.SAFTAnalyserLite.Views.SupplierView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:v="clr-namespace:FR.SAFTAnalyserLite.SAFT.Validations"
             xmlns:toolkit="http://schemas.xceed.com/wpf/xaml/toolkit"
             mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300">
    <DockPanel>
        <DockPanel.Resources>
            <CollectionViewSource x:Key="suppliers" Source="{Binding Suppliers, IsAsync=True}"/>
        </DockPanel.Resources>

        <toolkit:WatermarkTextBox 
            DockPanel.Dock="Top" Margin="3" TabIndex="2"
            Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged}"
            Watermark="Filtro por: Código fornecedor ou Nº conta ou NIF ou Nome ou Contacto ou Telefone ou Fax ou Email ou Website ou Autofacturação"/>
        
        <Button DockPanel.Dock="Bottom" Width="120" Height="25" Margin="5" Padding="3" HorizontalAlignment="Right" ToolTip="Exportar para Excel"
                Command="{Binding DoPrintCommand}"
                CommandParameter="{Binding ElementName=dataGridSuppliers}">
            <StackPanel Orientation="Horizontal">
                <Image Source="{StaticResource Excel}"/>
                <TextBlock Text="Fornecedores" Padding="5,0,0,0"/>
            </StackPanel>
        </Button>
        
        <DataGrid x:Name="dataGridSuppliers" DockPanel.Dock="Bottom" TabIndex="1"
                  ItemsSource="{Binding Source={StaticResource suppliers}}" >

            <DataGrid.RowValidationRules>
                <v:SupplierValidationRule ValidationStep="ConvertedProposedValue" ValidatesOnTargetUpdated="True"/>
            </DataGrid.RowValidationRules>

            <DataGrid.RowValidationErrorTemplate>
                <ControlTemplate>
                    <Grid Margin="0,-2,0,-2"
                          ToolTip="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGridRow}},
                        Path=(Validation.Errors)[0].ErrorContent}">
                        <Ellipse StrokeThickness="0" Fill="Red" 
                                 Width="{TemplateBinding FontSize}" 
                                 Height="{TemplateBinding FontSize}" />
                    </Grid>
                </ControlTemplate>
            </DataGrid.RowValidationErrorTemplate>

            <DataGrid.Columns>
                <DataGridTextColumn Header="Código fornecedor" Binding="{Binding SupplierID}" />
                <DataGridTextColumn Header="Nº conta" Binding="{Binding AccountID}" />
                <DataGridTextColumn Header="NIF" Binding="{Binding SupplierTaxID}" />
                <DataGridTextColumn Header="Nome" Binding="{Binding CompanyName}" />
                <DataGridTextColumn Header="Contacto" Binding="{Binding Contact}" />
                <DataGridTextColumn Header="Telefone" Binding="{Binding Telephone}" />
                <DataGridTextColumn Header="Fax" Binding="{Binding Fax}" />
                <DataGridTextColumn Header="Email" Binding="{Binding Email}" />
                <DataGridTextColumn Header="Website" Binding="{Binding Website}" />
                <DataGridTextColumn Header="Autofacturação" Binding="{Binding SelfBillingIndicator}" />
            </DataGrid.Columns>
        </DataGrid>
    </DockPanel>
</UserControl>
